package com.itheima.sys.mapper;

import com.itheima.sys.entity.SysFunction;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 系统功能表 系统-系统功能表 Mapper 接口
 * </p>
 *
 * @author itheima
 * @since 2020-12-13
 */
public interface SysFunctionMapper extends BaseMapper<SysFunction> {

    @Select("select DISTINCT\n" +
            "\tf.*\n" +
            "FROM\n" +
            "\t`company_user` cu\n" +
            "INNER JOIN company_user_role cur ON cur.company_user_id = cu.id\n" +
            "INNER JOIN sys_role r ON cur.role_id = r.id\n" +
            "INNER JOIN sys_role_function rf on rf.role_id = r.id\n" +
            "INNER JOIN sys_function f on rf.function_id = f.id\n" +
            "where cu.id = #{companyUserId}")
    List<SysFunction> queryFunctionsByCompanyUserId(@Param("companyUserId") Long companyUserId);


    @Select("SELECT f.* FROM `sys_role` r INNER JOIN sys_role_function rf on rf.role_id = r.id INNER JOIN sys_function f on rf.function_id = f.id where r.id = #{roleId} and r.company_id = #{companyId}")
    List<SysFunction> queryFunctionsByRoleId(@Param("roleId") Long roleId, @Param("companyId") Long companyId);
}
